package com.hskn.hss.module.eventtoremind.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.casesetissuesource.entity.CasesetIssueSource;
import com.hskn.hss.module.empPlan.mapper.EmpPlanMapper;
import com.hskn.hss.module.eventtoremind.entity.EventToRemind;
import com.hskn.hss.module.eventtoremind.mapper.EventToRemindMapper;
import com.hskn.hss.module.eventtoremind.service.IEventToRemindService;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 一张网提醒设置
 *
 * @author hskn
 * @since 2021-05-24
 */
@Slf4j
@RestController
@RequestMapping("/hss/eventtoremind")
public class EventToRemindController {

    @Autowired
    private IEventToRemindService eventToRemindService;

    /**
     * 添加
     *
     * @param request
     * @return
     */
    @SysLog(businessType = BusinessType.INSERT, tableName = "event_to_remind", bean = EventToRemind.class, beanMapper = EventToRemindMapper.class, names = "eventToRemindId")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public AjaxResult<Object> add(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            eventToRemindService.add(params);
            return AjaxResult.success("发布成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 编辑
     *
     * @param request
     * @return
     */
    @SysLog(businessType = BusinessType.UPDATE, tableName = "event_to_remind", idKey = "eventToRemindId", bean = EventToRemind.class, beanMapper = EventToRemindMapper.class, names = "eventToRemindId")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            eventToRemindService.mUpdate(params);
            return AjaxResult.success("修改成功");
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    /**
     * 详情
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "detail", method = RequestMethod.POST)
    public AjaxResult<Object> detail(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            EventToRemind eventToRemind = eventToRemindService.detail(params);
            return AjaxResult.success(eventToRemind);
        } catch (HssException e) {
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }
}

